package top.leix.springdemo.services.impl;
import org.springframework.stereotype.Service;
import top.leix.springdemo.NowSemester;
import top.leix.springdemo.Res;
import top.leix.springdemo.mapper.ClasstableMapper;
import top.leix.springdemo.mapper.LabMapper;
import top.leix.springdemo.pojo.MyReturn;
import top.leix.springdemo.services.CommonService;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
* @author 16435
* @description 针对表【apply_lab_student(学生申请表)】的数据库操作Service实现
* @createDate 2024-04-21 22:23:42
*/
@Service
public class CommonServiceImpl implements CommonService {
    @Resource
    private ClasstableMapper classtableMapper;
    @Resource
    private LabMapper labMapper;
    //返回自定义的排课表list
    @Override
    public Res queryMyReturn() {
        List<MyReturn> resultList = labMapper.selectLabWithClassSchedule(NowSemester.getNowSemester());
        //resultList包含周一到周五的实验室排课
        // 创建一个Map来存储按周几分组的排课信息
        Map<Integer, List<MyReturn>> weeklySchedule = new HashMap<>();
        for (int i = 1; i <= 5; i++) {
            weeklySchedule.put(i, new ArrayList<>()); // 初始化周一到周五的列表
        }
        // 遍历查询结果，将MyReturn对象按照weekDay字段的值放入对应的列表中
        for (MyReturn myReturn : resultList) {
            int weekDay = myReturn.getWeekDay(); // 假设MyReturn类有一个getWeekDay()方法
            if (weekDay >= 1 && weekDay <= 5) {
                weeklySchedule.get(weekDay).add(myReturn);
            }
        }
        List<List<MyReturn>> weeklyLists = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            weeklyLists.add(weeklySchedule.get(i));
        }
        return Res.ok(weeklyLists);
    }
}




